\documentclass[13pt]{article}
\usepackage{setspace}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{graphicx}

\setlength{\oddsidemargin}{0in}
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{9in}
\setlength{\textwidth}{6.5in}
\setlength{\baselineskip}{0in}

\newtheorem{thm}{Theorem}
\newtheorem{defn}{Definition}
\newtheorem{lem}{Lemma}
\newtheorem{cor}{Corollary}



\textwidth=6.5in
\textheight=8.8in
\oddsidemargin=0in
\evensidemargin=0in
\topmargin=-.6in
\headsep=.5in
\headheight=0.5in
\makeatletter
\def\@oddhead{\begin{minipage}[b]{\textwidth}
{\bf CS 6210 - AOS} 
\hfill 
Professor: {\em \professor} \\
CS 6210 Project Report: {\em \yournames} \hfill \thedate \\
\rule[9pt]{\textwidth}{0.5pt}
\end{minipage}}
\makeatother
\def\professor{Karsten Schwan}

%%%%%%%%%%%%%%%%%%%%%%%%%%      update your name below !!!!! %%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\yournames{Michael (Ding Ding) Xu and Shruthi Adappa}

\newcommand{\maxflow}{\text{MAXFLOW}}
\newcommand{\mincut}{\text{MINCUT}}
%\newtheorem{thm}{Theorem }
\newtheorem{prop} {Proposition }
%\newtheorem{lem}{Lemma}
%\newtheorem{cor}{Corollary}

\begin{document}
\doublespacing
%%%%%%%%% update title, names and date of your lecture below!!!!!  %%%%%%%%%%%%%%%%%%%%%
\def\thedate{March 1st, 2010}
\setcounter{page}{1}

\begin{center}
  {\bf \large CS 6210 - Project 2 Report}\\
\end{center}
\vskip.2in

\section{Approach}
\subsection{Locking}
The most critical component of the project is ensuring correct synchronization of read/write operations on the ring buffer. It was first noted that instances where there is only a single producer and a single consumer modifying the ring buffer can be unsynchronized. 

This is because both the producer and consumer require that they do not pass each other, which would result in an inconsistent state. Since reads by a server checking the producer guarantee that the producer will never move backwards towards the consumer, and a client read guarantees that the consumer will never move backwards towards the consumer, the read values are sufficient to guarantee that the producer and consumer will never overwrite each other. 

Thus, our server is completely singlethreaded, with no synchronization. The client is multithreaded (as per project requirements), using a single mutex to modify the producer value. This effectively makes the client a single producer. 

However, there are other race conditions remaining. Although there is a single producer, it must check that the thread that has previously placed a request and had its request serviced by the consumer has read its result before placing a new request on the ring buffer at that spot. To protect from race conditions involving unread results by the previous thread using a slot, each thread obtains a lock on a mutex corresponding to the position at the buffer ring, only releasing it after it has read its value. 

Thus, threads perform a pthread\_mutex\_trylock() on buffer ring mutexes when placing a request. When it does not successfully obtain a lock, it releases all locks, allowing other threads to try to obtain the lock. 

Originally, the client thread code was being starved, due to many threads attempting to obtain the lock, and only one thread having the lock and being able to unlock it. Thus, a semaphore was added, so that only a few threads would be running inside of the critical section and attempting to use the ring buffer. This increased performance greatly, avoiding halts in execution of the client.

All of the client buffer ring code was written in buff\_wait(), which synchronously calls and receives on the buffer ring. 
\subsection{Client}
The client starts by placing a message on a predetermined message queue. The message is the shmid of the shared memory segment on which it plans to communicate to the server. It then launches threads, each performing a number of rounds, each of which communicates with the server a certain number of times, at a certain interval. All of the program parameters are command line specified.

The client uses the synchronization scheme discussed above. 
\subsection{Server}
The server 

\section{Results}



\end{document}



